import axios from 'axios'
import http from './http'

export default {
  uploadImage (data) {
    const headers = {
      'content-type': 'application/hal+json',
      'X-Drupal-REST-File': 1
    }
    const pack = {
      ...data,
      type: [{ target_id: 'image' }],
      _links: {
        type: {
          href: `${http.baseURL}rest/type/file/image`
        }
      }
    }
    return axios.post(`entity/file?_format=hal_json`, pack, { headers })
  },

  uploadDocument (data) {
    const headers = {
      'content-type': 'application/hal+json',
      'X-Drupal-REST-File': 1
    }
    const pack = {
      ...data,
      type: [{ target_id: 'document' }],
      _links: {
        type: {
          href: `${http.baseURL}rest/type/file/document`
        }
      }
    }
    return axios.post(`entity/file?_format=hal_json`, pack, { headers })
  }
}
